<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml"
	  xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
	  layout:decorator="layout">
	<body>
	<section layout:fragment="content">
		<div class="bgf">
			<div class="width90 margin0auto even">
				<span class="bth9b">*</span>年级
				<div class="write-inp">
					<input id="grade" type="tel" />		
				</div>
			</div>
		</div>
		<div class="bgf">
			<div class="width90 margin0auto even seDept" style="display: none;">
				<span class="bth9b">*</span>院系
				<div class="write-inp">
					<select id="department">
						<option>请选择您的院系</option>
						<option>xxxxx1</option>
						<option>xxxx2</option>
					</select>					
				</div>
			</div>
		</div>
		<p style="text-align: right;width: 90%;margin: 0 auto;font-size: .8rem;">请选择自己的年级和院系，为院系增光添彩</p>
		
		<div class="rbtn give-redcard">提交</div>
		<script>
			$(function(){
				var $grade = $("#grade"),
					$department = $("#department"),
					$seDept = $(".seDept"),
					$submint = $(".give-redcard");
					sYear = 1949,
					eYear = new Date().getMonth()+1 >=9?new Date().getFullYear():new Date().getFullYear()-1;
					console.log(eYear)
					$grade.on("blur",function(){
						var _y = $(this).val();

						if(sYear > _y || _y > eYear){
							alert("请输入正确的年级");
						}else{
							$.ajax({
								url:"/static/json/index8.json?grade="+_y,
								type:"GET",
								dataType:"json",
								success:function(d){
									if(d){
										var _options = "<option>请选择您的院系</option>"
										for(var i= 0;d[_y].length > i;i++){
											_options+="<option>"+d[_y][i]+"</option>";
										}
										$department.html(_options);
									}
								},
								error:function(a,b,c){

								}
							})
							$seDept.show();
						}
					});

					$submint.on("click",function () {


						if($("#grade").val()==null||$("#grade").val()==""||$department.val()==null||$department.val()==""||$department.val()=="请选择您的院系"){
							alert("请完善所在院系信息!");
							return;
						}

						var callId = /*[[${callId}]]*/'';
						var  data ={'callId':callId,'grade':$grade.val(),'department':$department.val(),'code':"120"};
						$.ajax({
							url:"/peking/user/saving",
							type:"POST",
							contentType: 'application/json',
							data:JSON.stringify(data),
							success:function(res){
								window.location.href = "/peking/thanks?callId="+callId;
							},
							error:function(a,b,c){
								alert("保存失败请重试!");
							}
						})
						$seDept.show();
					});

			})
		</script>
	</section>
	</body>
</html>
